<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>component</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <yuan></yuan>
        <yuan></yuan>
        <lei></lei>
    </div>
    <script>
        Vue.component("yuan",{
            template:`<h2 @click="add">hello{{count}}</h2>`,
            data(){
                return{
                    count:1
                }
            },
            methods:{
                add(){
                    this.count++;
                }
            }
        })
        var vm=new Vue({
                el:"#app",
                components:{
                    "lei":{
                            template:`
                           <div class="box">
                            <div v-for="(v,i) in nlist">
                            <span>{{i+1}}</span>
                            <span>{{v.title}}</span>
                            <button @click="del(i)">删除</button>
                            </div>
                            </div>`,
                            data:function()
                    {
                            return{
                                nlist:[
                                    {id:1,title:"这里是标题1"},
                                    {id:2,title:"这里是标题2"},
                                    {id:3,title:"这里是标题3"},
                                    {id:4,title:"这里是标题4"},
                                    {id:5,title:"这里是标题5"},

                                ]
                                    }
                    },
                    methods:{
                        del(index){
                            this.nlist.splice(index,1);
                        }
                    }
                            }
                }
                        })
    </script>
</body>
</html>